const App = getApp();

Page({

  data: {
    // 页面参数
    options: {},
    // 页面元素
    items: {},
    // current_area:App.globalData.current_area,
    current_area:wx.getStorageSync('shop_name')?wx.getStorageSync('shop_name'):"请选择菜场",
    floorstatus: false, // 返回顶部
    // right: '24rpx',
    // bottom:'80rpx',
    height:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 当前页面参数
    this.setData({
      options
    });
    // 加载页面数据
    this.getPageData();
    console.log(wx.getStorageSync('shop_name'))
    if(wx.getStorageSync('shop_name')== ''){
      wx.navigateTo({
        url: '/pages/shopselect/shopselect',
      })
    }
    // 获取页面高度
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        let clientHeight = res.windowHeight;
        let clientWidth = res.windowWidth;
        let ratio = 750 / clientWidth;
        let height = clientHeight * ratio;
        that.setData({
          height: height+'px'
        });
        console.log(height)
      }
    });



    wx.getLocation({
      type: 'wgs84',
      success (res) {
        console.log(res)
        const latitude = res.latitude
        const longitude = res.longitude
        
        App._get('page/index', {
          page_id:'10003'
        }, result => {
          // 设置顶部导航栏栏
          var ShopItem = result.data.items[0].data;
          console.log(ShopItem);
          // 回调函数
          typeof callback === 'function' && callback();
        });
      }
     })
  },
  onShow(){
    console.log('当前页面显示')
  },
  onHide(){
    console.log('当前页面隐藏')
  },
  onUnload(){
    console.log('当前页面卸载')
  },
  /**
   * 加载页面数据
   */
  getPageData(callback) {
    let _this = this;
    App._get('page/index', {
      page_id: _this.data.options.page_id || 0
    }, result => {
      // 设置顶部导航栏栏
      _this.setPageBar(result.data.page);
      result.data.items[0].current_area = '盛世铭都'
      _this.setData(result.data); 
      console.log(result.data)
      // 回调函数
      typeof callback === 'function' && callback();
    });
  },




  /**
   * 设置顶部导航栏
   */
  setPageBar(page) {
    // 设置页面标题
    wx.setNavigationBarTitle({
      title: page.params.title
    });
    // 设置navbar标题、颜色
    wx.setNavigationBarColor({
      frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
      backgroundColor: page.style.titleBackgroundColor
    })
  },

  /**
   * 下拉刷新
   */
  onPullDownRefresh() {
    // 获取首页数据
    this.getPageData(function () {
      wx.stopPullDownRefresh();
    });
  },
  /**
   * 返回顶部
   */
  onScrollTop() {
    let _this = this;
    _this.setData({
      scrollTop: 0
    });
  },
   /**
   * 显示/隐藏 返回顶部按钮
   */
  scroll(e) {
    let _this = this;
    _this.setData({
      floorstatus: e.detail.scrollTop > 10
    })
  },
  /**
   * 分享当前页面
   */
  onShareAppMessage() {
    const _this = this;
    return {
      title: _this.data.page.params.share_title,
      path: "/pages/index/index?" + App.getShareUrlParams()
    };
  },

  /**
   * 分享到朋友圈
   * 本接口为 Beta 版本，暂只在 Android 平台支持，详见分享到朋友圈 (Beta)
   * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
   */
  onShareTimeline() {
    const _this = this;
    return {
      title: _this.data.page.params.share_title,
      path: "/pages/index/index?" + App.getShareUrlParams()
    };
  }

});